package xuesm.proxy.dynamic.jdk;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * @Author: xuesm
 * @Description: JDK动态代理
 * @Date: Create in 20:16 2019/4/2
 */
public class JDKAgent implements InvocationHandler{


	private Object object;
	public Object getInstance(Object object) throws Exception{

		this.object = object;
		Class<?> clazz = object.getClass();
		return Proxy.newProxyInstance(clazz.getClassLoader(), clazz.getInterfaces(), this);
	}



	@Override
	public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
		before();
		Object  obj = method.invoke(this.object, args);
		after();
		return obj;
	}

	private void after() {
		System.out.println("安排明星（体育， 演员）衣食住行");
	}

	private void before() {
		System.out.println("（给运动员）联系俱乐部，或者（给演员）联系公司接剧本");
	}

}
